# coding=utf-8

import sys
import os
import subprocess

print(sys.argv)
exePath = sys.argv[0]
(curPath, fileName) = os.path.split(exePath)
fromPath = sys.argv[2]
targetPath = sys.argv[4]
fromPath = fromPath.replace("/", "\\")
targetPath = targetPath.replace("/", "\\")

pvrType = sys.argv[12]
print(f'quality1: {pvrType}')
astcType = '8x8' if pvrType == 'PVRTC1_2,UBN,lRGB' else '4x4'
print(f'astcType1: {astcType}')
# 'PVRTC1_2,UBN,lRGB'
# 'PVRTC1_4,UBN,lRGB'

# fileDir, fileName = os.path.split(fromPath)
# extName = fileName.split(".")[1]

targetFileDir, targetFileName = os.path.split(targetPath)
splitName = targetFileName.split(".")[0]
# newPath = targetFileDir + "\\" + splitName + "." + extName + "jie"
newPath = targetFileDir + "\\" + splitName + ".astc"


# status = subprocess.call("copy " + fromPath + " " + newPath + " >nul", shell=True)
# astcenc -cl E:\debug\NewProject_1\testCCC331\build\wechatgame\assets\main\native\89\89df9257-876d-4002-9799-b61357002e25.jpg E:\debug\NewProject_1\testCCC331\build\wechatgame\assets\main\native\89\89df9257-876d-4002-9799-b61357002e25.astc 8x8 -medium
# status = subprocess.call(curPath + "\\astcenc-sse2 -cl " + fromPath + " " + newPath + " 6x6 -medium", shell=True)
# status = subprocess.call(f'{curPath}\\astcenc-sse2 -cl {fromPath} {newPath} {astcType} -medium', shell=True)
# if status != 0:
#     if status < 0:
#         print("Killed by signal", status)
#     else:
#         print("Command failed with return code - ", status)


# 拷贝文件
# if pvrType == 'PVRTC1_2,UBN,lRGB':
#     print("astc: " + fromPath + " " + newPath)
#     status = subprocess.call(f'{curPath}\\astcenc-sse2 -cl {fromPath} {newPath} {astcType} -medium', shell=True)
# else: 
#     print("copy: " + fromPath + " " + targetPath)
    # fileDir, fileName = os.path.split(fromPath)
    # extName = fileName.split(".")[1]
    # newPath = targetFileDir + "\\" + splitName + "." + extName + "jie"
    # status = subprocess.call("copy " + fromPath + " " + newPath + " >nul", shell=True)
    
status = subprocess.call(f'{curPath}\\astcenc-sse2 -cl {fromPath} {newPath} {astcType} -medium', shell=True)
if status != 0:
    if status < 0:
        print("Killed by signal", status)
    else:
        print("Command failed with return code - ", status)